package com.sky.mapper;

import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ShoppingCartMapper {

    //1.先根据用户id+套餐/菜品从购物车表查询
    ShoppingCart findOne(ShoppingCart shoppingCart);

    //购物车保存
    @Insert("insert into shopping_cart values (null,#{name},#{image},#{userId},#{dishId},#{setmealId},#{dishFlavor},#{number},#{amount},#{createTime})")
    void save(ShoppingCart shoppingCart);

    //购物车更新
    void update(ShoppingCart shoppingCart);

    //查询购物车
    @Select("select *  from shopping_cart where user_id=#{userId}")
    List<ShoppingCart> findByUserId(Long userId);

    //清空购物车
    @Delete("delete from shopping_cart where user_id=#{userId}")
    void deleteByUserId(Long userId);

    //删除购物车菜品或套餐
    void delete(ShoppingCart shoppingCart);

}
